/**
 * 
 */
package com.pactera.integral.controller;

import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pactera.integral.common.repository.QueryResult;
import com.pactera.integral.common.repository.ResultMap;
import com.pactera.integral.common.web.GenericController;
import com.pactera.integral.common.web.Response;
import com.pactera.integral.entity.User;
import com.pactera.integral.service.UserService;

/**
 * @author TempUser
 *
 */
@Controller
@RequestMapping("/adm/user")
public class UserController extends GenericController {
	@Resource
	private UserService userService;

	/**
	 * 用户列表
	 * 
	 * @param param
	 * @param pageable
	 * @return Response
	 */
	@PostMapping("/page")
	@ResponseBody
	public Response getUserPage(@RequestBody HashMap<String, Object> param, Pageable pageable) {
		QueryResult<ResultMap<String, Object>> queryResult = userService.searchUserList(param, pageable);

		return this.normal(queryResult);
	}

	/**
	 * 添加或修改用户
	 * 
	 * @param user
	 * @return Response
	 */
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	@ResponseBody
	public Response save(@RequestBody User user) {

		return this.normal(userService.saveUser(user));
	}

	/**
	 * 删除用户
	 * 
	 * @param userId
	 * @return Response
	 */
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
	@ResponseBody
	public Response delete(@RequestParam(value = "userId", required = false) String userId) {

		return this.normal(userService.deleteUser(userId));
	}

	/**
	 * 查看用户明细
	 * 
	 * @param userId
	 * @return Response
	 */
	@RequestMapping(value = "/userDetails", method = RequestMethod.GET)
	@ResponseBody
	public Response getGroup(@RequestParam(value = "userId", required = false) String userId) {

		return this.normal(userService.getUser(userId));
	}
	
	/**
	 * 查看用户详情
	 * 
	 * @param userId
	 * @return Response
	 */
	@RequestMapping(value = "/detail", method = RequestMethod.GET)
	@ResponseBody
	public Response getDetail(@RequestParam(value = "userId", required = false) String userId) {

		return this.normal(userService.getUser(userId));
	}
}
